import React from 'react'
import ReactDOM from 'react-dom/client'

import App from './App'
import mitt from 'mitt'

class EventBus {
  constructor() {
    this.bus = mitt()
  }

  on(event, handler) {
    this.bus.on(event, handler)
  }

  emit(event, ...args) {
    this.bus.emit(event, ...args)
  }
}

// !#1 往 React.Component 上面挂载 emitter 熟悉
// React.Component.prototype.emitter = mitt()
React.Component.prototype.emitter = new EventBus()

ReactDOM.createRoot(document.getElementById('root')).render(<App />)
